/**
 * 
 */
package systole.view.crud.tableModels;

import java.util.List;

import systole.domain.clinicalInformation.Medicine;
import systole.domain.clinicalInformation.MedicinePatient;

/**
 * @author jmj
 * 
 */
public class MedicinesByPatienteTableModel extends SystoleTableModel<MedicinePatient> {

    private String[] columnNames = {"Medicamento", "Dósis", "Desde hace [años]"};
    private static final int MEDICINE_INDEX = 0;
    private static final int DOSAGE_INDEX = 1;
    private static final int INIT_INDEX = 2;

    /**
     * @param medicines
     *
     */
    public MedicinesByPatienteTableModel(List<MedicinePatient> medicines) {
        super(medicines);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnClass(int)
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case MEDICINE_INDEX:
                return Medicine.class;
            case DOSAGE_INDEX:
                return String.class;
            case INIT_INDEX:
                return Integer.class;
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case MEDICINE_INDEX:
                return this.entities.get(rowIndex).getMedicine();
            case DOSAGE_INDEX:
                return this.entities.get(rowIndex).getDosage();
            case INIT_INDEX:
                return this.entities.get(rowIndex).getAgeAtStartAsInteger();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case MEDICINE_INDEX:
                this.entities.get(rowIndex).setMedicine((Medicine) aValue);
                break;
            case DOSAGE_INDEX:
                this.entities.get(rowIndex).setDosage((String) aValue);
                break;
            case INIT_INDEX:
                this.entities.get(rowIndex).setAgeAtStartAsInteger((Integer) aValue);
                break;
        }
    }
}
